package nl.saxion.ein4b;

import java.util.ArrayList;
import java.util.Collections;

import nl.saxion.ein4b.model.Profile;
import nl.saxion.ein4b.model.ProfileManager;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class HighscoreActivity extends Activity {
	ProfileManager m;
	ArrayList<Profile> profiles;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.highscores);

		m = new ProfileManager(this.getBaseContext());
		profiles = m.loadProfiles();

		Collections.sort(profiles);

		ArrayList<String> profileNames = new ArrayList<String>();
		for (Profile p : profiles) {
			profileNames.add(p.getName() + "    Coins: " + p.getCredit()
					+ "    Games Played: " + p.getNumGamesPlayed());
		}
		String[] values = new String[profileNames.size()];
		for (int i = 0; i < profileNames.size(); i++) {
			values[i] = profileNames.get(i);
		}

		ListView lv = (ListView) findViewById(R.id.list_view);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, values);
		lv.setAdapter(adapter);
	}

}
